﻿Public Class StuAnswerDisplay
    Dim stuId As Integer
    Dim stuName As String
    Dim examName As String
    Dim examScore As String
    Dim stuExamTime As String
    Dim stuScore As String
    Dim examId As Integer
    Dim questionCount As Integer

    Public Property StudId As Integer
        Get
            Return stuId
        End Get
        Set(value As Integer)
            stuId = value
        End Set
    End Property

    Public Property StudScore As String
        Get
            Return stuScore
        End Get
        Set(value As String)
            stuScore = value
        End Set
    End Property

    Public Property StudName As String
        Get
            Return stuName
        End Get
        Set(value As String)
            stuName = value
        End Set
    End Property

    Public Property ExamsName As String
        Get
            Return examName
        End Get
        Set(value As String)
            examName = value
        End Set
    End Property

    Public Property ExamsScore As String
        Get
            Return examScore
        End Get
        Set(value As String)
            examScore = value
        End Set
    End Property

    Public Property StuJoinTime As String
        Get
            Return stuExamTime
        End Get
        Set(value As String)
            stuExamTime = value
        End Set
    End Property

    Public Property ExamsId As Integer
        Get
            Return examId
        End Get
        Set(value As Integer)
            examId = value
        End Set
    End Property

    Private Sub StuAnswerDisplay_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lblExamName.Text = examName
        lblExamTime.Text = stuExamTime
        lblTotalScore.Text = examScore
        lblStuName.Text = stuName
        lblStuScore.Text = stuScore
        Try
            Me.View_question_answerTableAdapter1.FillByExamAndStuId(Me.ExamDataSet1.view_question_answer, examId, stuId)
            ShowData()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ShowData()
        Dim row As ExamDataSet.view_question_answerRow
        Dim correctCount As Integer = 0
        Dim wrongCount As Integer = 0
        Dim totalCount As Integer = Me.ExamDataSet1.view_question_answer.Count
        If totalCount > 0 Then
            For Each row In Me.ExamDataSet1.view_question_answer.Rows
                If row.score = 0 Then
                    wrongCount = wrongCount + 1
                Else
                    correctCount = correctCount + 1
                End If
            Next
        End If
        lblQueCount.Text = totalCount.ToString()
        lblRightCount.Text = correctCount.ToString()
        lblWrongCount.Text = wrongCount.ToString()
    End Sub

    Private Sub dgvQuestions_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvQuestions.CellClick
        If e.RowIndex >= 0 Then
            refreshDetail(e.RowIndex)
        End If

    End Sub

    Private Sub refreshDetail(rowIndex As Integer)
        Dim row As DataGridViewRow = dgvQuestions.Rows(rowIndex)
        Dim type As Integer = row.Cells("type").Value
        lblQueTitle.Text = row.Cells("title").Value
        rtbQuestion.Text = row.Cells("question").Value.ToString().Replace("[[]]", "________")
        Select Case type
            Case 0
                lblQuestionType.Text = "选择题"
                Dim options As String() = row.Cells("options").Value.ToString().Split(ExamGlobal.Spliter, StringSplitOptions.RemoveEmptyEntries)
                If options.Count = 4 Then
                    rtbQuestion.Text += System.Environment.NewLine
                    rtbQuestion.Text += System.Environment.NewLine
                    rtbQuestion.Text += "A: " + options(0)
                    rtbQuestion.Text += System.Environment.NewLine
                    rtbQuestion.Text += "B: " + options(1)
                    rtbQuestion.Text += System.Environment.NewLine
                    rtbQuestion.Text += "C: " + options(2)
                    rtbQuestion.Text += System.Environment.NewLine
                    rtbQuestion.Text += "D: " + options(3)
                    rtbQuestion.Text += System.Environment.NewLine
                    lblRightAnswer.Text = row.Cells("right_answer").Value.ToString().ToUpper()
                    lblStudentAnswer.Text = row.Cells("stu_answer").Value.ToString().ToUpper()
                End If

            Case 1
                lblQuestionType.Text = "判断题"
                If row.Cells("right_answer").Value.Equals("0") Then
                    lblRightAnswer.Text = "错误"
                Else
                    lblRightAnswer.Text = "正确"
                End If
                If row.Cells("stu_answer").Value.Equals("0") Then
                    lblStudentAnswer.Text = "错误"
                Else
                    lblStudentAnswer.Text = "正确"
                End If
            Case 2
                lblQuestionType.Text = "填空题"
                lblRightAnswer.Text = row.Cells("right_answer").Value.ToString().Replace("||", "    ")
                lblStudentAnswer.Text = row.Cells("stu_answer").Value.ToString().Replace("||", "    ")
        End Select
        lblIsCorrect.Text = row.Cells("score").Value
        lblQueOrgScore.Text = row.Cells("org_score").Value
    End Sub

    Private Sub dgvQuestions_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles dgvQuestions.DataBindingComplete
        Dim row As DataGridViewRow
        Dim rowCount = 1
        If Me.ExamDataSet1.view_question_answer.Count > 0 Then
            For Each row In dgvQuestions.Rows
                row.Cells("questionNo").Value = rowCount
                rowCount = rowCount + 1
            Next
            refreshDetail(0)
        End If
    End Sub
End Class